import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

private static final Logger logger = LoggerFactory.getLogger(MyClass.class);

void performTask(){
      try{
          someOperation();
      }catch(Exception ex){
           logger.error("An error occurred while performing task.",ex);
           handleFailure(ex.getMessage());
      }
}